package com.joy.conf.mvc;

import com.google.common.collect.Lists;
import com.joy.common.interceptor.DrawInterceptor;
import com.joy.common.interceptor.LoginInterceptor;
import com.joy.common.interceptor.PageInitInterceptor;
import com.joy.common.interceptor.PermissionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;


@Configuration
public class WebMvcInterceptorConfig implements WebMvcConfigurer {
	
	@Autowired
	private LoginInterceptor loginInterceptor;
	@Autowired
	private PageInitInterceptor pageInitInterceptor;
	@Autowired
	private PermissionInterceptor permissionInterceptor;
	@Autowired
	private DrawInterceptor drawInterceptor;


	public void addInterceptors(InterceptorRegistry registry) {

		//登录拦截器
		List<String> loginInterceptorExcludeList = Lists.newArrayList();
		loginInterceptorExcludeList.add("/decorator/index");
		loginInterceptorExcludeList.add("/error");
		loginInterceptorExcludeList.add("/assets/**");
		loginInterceptorExcludeList.add("/jstree/**");
		loginInterceptorExcludeList.add("/common/**");
		loginInterceptorExcludeList.add("/login");
		loginInterceptorExcludeList.add("/login/**");
		registry.addInterceptor(loginInterceptor)
				.excludePathPatterns(loginInterceptorExcludeList);

		//权限过滤
		List<String> shiroExcludeList = Lists.newArrayList();
		shiroExcludeList.add("/decorator/index");
		shiroExcludeList.add("/error");
		shiroExcludeList.add("/assets/**");
		shiroExcludeList.add("/jstree/**");
		shiroExcludeList.add("/common/**");
		shiroExcludeList.add("/login");
		shiroExcludeList.add("/login/**");
		shiroExcludeList.add("/file/**");
		registry.addInterceptor(permissionInterceptor)
				.addPathPatterns("/**")
				.excludePathPatterns(shiroExcludeList);

		//页面初始化
		List<String> pageInterceptorExcludeList = Lists.newArrayList();
		pageInterceptorExcludeList.add("/decorator/index");
		pageInterceptorExcludeList.add("/error");
		pageInterceptorExcludeList.add("/assets/**");
		pageInterceptorExcludeList.add("/jstree/**");
		pageInterceptorExcludeList.add("/common/**");
		pageInterceptorExcludeList.add("/login");
		pageInterceptorExcludeList.add("/login/**");
		registry.addInterceptor(pageInitInterceptor)
				.excludePathPatterns(pageInterceptorExcludeList);

		//搜索项返回拦截器
		List<String> drawInterceptorExcludeList = Lists.newArrayList();
		drawInterceptorExcludeList.add("/decorator/index");
		drawInterceptorExcludeList.add("/error");
		drawInterceptorExcludeList.add("/assets/**");
		drawInterceptorExcludeList.add("/jstree/**");
		drawInterceptorExcludeList.add("/common/**");
		drawInterceptorExcludeList.add("/login");
		drawInterceptorExcludeList.add("/login/**");
		registry.addInterceptor(drawInterceptor)
				.excludePathPatterns(drawInterceptorExcludeList);


	}
}
